<?php
// +----------------------------------------------------------------------
// | MyCentOS
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.mycentos.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 琥珀 <317559272@qqq.com><http://www.mycentos.com>
// +----------------------------------------------------------------------
// | @date  : 2015-04-09 11:07:40
// +----------------------------------------------------------------------
// | @Last Modified by:  琥珀
// +----------------------------------------------------------------------
// | @Last Modified time: 2015-04-20 16:30:24
// +-----------------------------------------------------------------------
/**
 * 公共函数库
 */
//打印函数
function p($value){
    echo "<pre>";
    print_r($value);
    echo "</pre>";
}

function is_login() {
    $user = session('user_auth');
    if (empty($user)) {
        return 0;
    } else {
        return $user['uid'];
    }
}
function check_verify($code, $id = ''){
    $verify = new \Think\Verify();
    return $verify->check($code, $id);
}

function get_category_list ($class, $html = '--', $pid = 0, $level = 0) {
            $arr = array();
            foreach ($class as $k => $v) {
                if ($v['pid'] == $pid) {
                    $v['level'] = $level + 1;
                    $v['html']  = str_repeat($html, $level);
                    $arr[] = $v;

                    $arr = array_merge($arr, get_category_list($class, $html, $v['id'], $level + 1));
                }
            }
            return $arr;
}
function getallchildcateids($categoryID)
    {
        //初始化ID数组
        $array[] = $categoryID;
        do
        {
            $ids = '';
            $where['pid'] = array('in',$categoryID);
            $cate = M('Category')->where($where)->select();
            foreach ($cate as $k=>$v)
            {
                $array[] = $v['id'];
                $ids .= ',' . $v['id'];
            }
            $ids = substr($ids, 1, strlen($ids));
            $categoryID = $ids;
        }
        while (!empty($cate));
        $ids = implode(',', $array);
        //return $ids;    //  返回字符串
        return $array; //返回数组
    }
//获取分类名称
function get_category_name($category_id = null) {
    if (!$category_id) {
        return;
    }
    $map['id'] = $category_id;
    $category_name = M('Category')->where($map)->getField('name');
    return $category_name;
}


?>